<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>zyupload上传实例</title>
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="<<<.carousel_info.Title>>>" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">URL</label>
        <div class="layui-input-block">
            <input type="text" name="url" value="<<<.carousel_info.Url>>>" placeholder="请输入url链接" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章id</label>
        <div class="layui-input-block">
            <input type="text" name="article_id" value="<<<.carousel_info.ArticleId>>>" placeholder="请输入文章id" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="启用" <<<if eq .carousel_info.Status 0 >>>checked=""<<<end>>>>
            <input type="radio" name="status" value="1" title="停用" <<<if eq .carousel_info.Status 1 >>>checked=""<<<end>>>>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">上传图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="image">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            <input type="hidden" name="image_url" id="image_url" value="<<<.carousel_info.ImageUrl>>>">
            <input type="hidden" name="id" value="<<<.carousel_info.Id>>>">
        </div>
    </div>
</div>
<script src="/static/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/layuimini/lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script type="text/javascript">
    $(function () {
        layui.use(['jquery', 'upload','form'], function(){
            var upload = layui.upload;
            var $ = layui.jquery,
                form = layui.form;

            //执行实例
            var uploadInst = upload.render({
                elem: '#image' //绑定元素
                ,url: '/admin/ajax_upload_carousel' //上传接口
                ,done: function(res){
                    if(res.code == 10000){
                        $("#image_url").val(res.data);
                    }
                    layer.msg(res.msg);
                }
                ,error: function(){
                    //请求异常回调
                }
            });

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                data = data.field
                $.ajax({
                    url: "/admin/ajax_edit_carousel",
                    data:{id:data.id,image_url:data.image_url,title:data.title,url:data.url,status:data.status,article_id:data.article_id},
                    type:"POST",
                    success: function(data){
                        layer.msg(data.msg);
                        if(data.code == 10000){
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);

                            parent.layui.table.reload('currentTableId',{page:{curr:1}}); //demo表格id
                        }

                    }
                });

                return false;
            });
        });

    });
</script>

</body>
</html>